'use strict';
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
const { promisify } = require('util');
const name = require('../../package').name;
const downloadGitRepo = promisify(require('download-git-repo'));

const spinner = require('./spinner.js');

const loadRemoteParset = async (repo) => {
  const tmpdir = path.join(os.tmpdir(), name);
  await fs.remove(tmpdir);
  await downloadGitRepo(repo, tmpdir, { clone: true }).catch(err => {
    console.log(err);
  });
  return tmpdir;
}

module.exports = spinner(loadRemoteParset, '模板下载中...');
